/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   14.05.2010
 * @version SVN: $Id: RecipeRepositoryImpl.java 140 2010-05-15 11:59:46Z christian-kerl@web.de $
 */
package org.cakis.server.model.repository.impl;

import java.util.List;
import java.util.UUID;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.cakis.server.Names;
import org.cakis.server.model.Recipe;
import org.cakis.server.model.repository.RecipeRepository;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

/**
 * RecipeRepositoryImpl
 *
 * @author Christian Kerl
 */
@Name(Names.RecipeRepository)
@AutoCreate
@Stateless(name = Names.RecipeRepository)
public class RecipeRepositoryImpl extends AbstractRepository<Recipe> implements RecipeRepository {

    @Override
    protected Long getId(Recipe object) {
        return object.getId();
    }

    @Override
    public List<Recipe> findAllOrderByName() {
        Query q = em.createQuery("select r from Recipe r order by r.name");

        return list(q);
    }

    @Override
    public Recipe findByUuid(UUID id) {
        Query q = em.createQuery("select r from Recipe r where r.internalUuid = :uuid");
        q.setParameter("uuid", id.toString());

        return one(q);
    }
}
